package com.we823.project.controller.base;

import org.apache.commons.lang3.StringUtils;

import com.we823.project.controller.PermissionList;
import com.we823.project.common.web.status.PermissionStatus;

public class AbstractPermissionBaseController {
	private PermissionList permissionList=null;
	
	public PermissionList getPermissionList() {
		return this.permissionList;
	}
	
	/**
     * 权限前缀：如sys:user
     * 则生成的新增权限为 sys:user:create
     */
    public void setResourceIdentity(String resourceIdentity) {
        if (!StringUtils.isEmpty(resourceIdentity)) {
            permissionList = PermissionList.newPermissionList(resourceIdentity);
        }
    }
    
    public void check(PermissionStatus permissionStatus) {
		if (permissionList!=null) {
			switch (permissionStatus) {
			case CREATE:
				permissionList.assertHasCreatePermission();
				break;
			case UPDATE:
				permissionList.assertHasUpdatePermission();
				break;
			case DELETE:
				permissionList.assertHasDeletePermission();
				break;
			case VIEW:
				permissionList.assertHasViewPermission();
				break;
			default:
				permissionList.assertHasCreatePermission();
				permissionList.assertHasUpdatePermission();
				permissionList.assertHasDeletePermission();
				permissionList.assertHasViewPermission();
				break;
			}
		}
	}
}
